#include <stdio.h>

int main(){
    FILE *fp1,*fp2;
    char buffer[BUFSIZ],str[50];
    fpos_t p;
    setbuf(stdout,buffer);
    fp1=fopen("std_stream.c","r");
    printf("%d\n",ftell(fp1));
    fgets(str,50,fp1);
    fgetpos(fp1,&p);
    printf("%d\n",p);
    fseek(fp1,0,SEEK_END);
    fsetpos(fp1,&p);
    rewind(fp1);
    setvbuf(stdout,buffer,_IOFBF,1024);
    fp2=freopen("copy.txt","w",stdout);
    fgets(str,10,fp1);
    fputs(str,stdout);
    fflush(stdout);
    if(ferror(fp1)==0){
        fgets(str,10000,fp1);
        fputs(str,stdout);
    }
    perror("Error: ");
    clearerr(fp1);
    if(feof(fp1)){
        fclose(fp1);
    }
    fclose(fp2);
    return 0;
}
